package 滑动窗口.无重复字符的最长子串3;

import utils.Utils;

import java.util.HashSet;
import java.util.Set;

public class Solution {

    public static int lengthOfLongestSubstring(String s) {
        int res = 0;
        Set<Character> set = new HashSet<>();

        for(int i=0,j=0;i<s.length();i++){
            if(i>0){
                set.remove(s.charAt(i-1));
            }
            while(j<s.length() && !set.contains(s.charAt(j))){
                set.add(s.charAt(j));
                j++;
            }
            res = Math.max(res,set.size());
        }


        return res;
    }

    public static void main(String[] args) {
        String s = "";
        Utils.printInt(lengthOfLongestSubstring(s));
    }
}
